FROM php:7.3-apache
WORKDIR /var/www/laravel

RUN curl -sS https://getcomposer.org.mirrors.china-speed.org.cn/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN find /etc/apt/ -name "*.list" -print0 | xargs -0 sed -i 's/[a-z]\+.debian.org/mirrors.aliyun.com/g'
RUN apt-get update \
    && apt-get install -y \
    cron \
    icu-devtools \
    jq \
    libfreetype6-dev libicu-dev libjpeg62-turbo-dev libpng-dev libsasl2-dev libssl-dev libwebp-dev libxpm-dev libzip-dev \
    nodejs \
    unzip \
    zlib1g-dev
RUN apt-get clean \
    && apt-get autoclean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
    && yes '' | pecl install redis \
    && docker-php-ext-install intl pdo_mysql zip \
    && docker-php-ext-enable opcache redis

COPY composer.json /var/www/laravel/
COPY composer.lock /var/www/laravel/
RUN composer install --no-autoloader --no-scripts --no-dev

COPY app /var/www/laravel/app
COPY artisan /var/www/laravel/artisan
COPY bootstrap /var/www/laravel/bootstrap
COPY config /var/www/laravel/config
COPY database /var/www/laravel/database
COPY public /var/www/laravel/public
COPY resources /var/www/laravel/resources
COPY routes /var/www/laravel/routes
COPY server.php /var/www/laravel/server.php
COPY storage /var/www/laravel/storage
RUN composer install --optimize-autoloader --no-dev

RUN rm -f public/storage \
    && php artisan storage:link \
    && touch database/database.sqlite

COPY docker/ /
RUN a2enmod rewrite headers \
    && a2ensite laravel \
    && a2dissite 000-default

COPY . /var/www/laravel/
RUN chown www-data:www-data bootstrap/cache \
    && chown -R www-data:www-data storage/

CMD ["docker-laravel-entrypoint"]
